<script setup>
import { ref, reactive, watch, onBeforeMount } from 'vue'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const typeActions = ref([

])
const dateActions = ref([
  { text: t('bill_week'), id: 1 },
  { text: t('bill_oneMonth'), id: 2 },
  { text: t('bill_trimester'), id: 3 },
  { text: t('bill_halfAYear'), id: 4 },
  { text: t('bill_oneYear'), id: 5 }
])
const showTypePopover = ref(false)
const showDatePopover = ref(false)
const selectData = reactive({
  type: 1,
  date: 1
})
const onTypeSelect = ({ id }) => {
  selectData.type = id
}
const onDateSelect = ({ id }) => {
  selectData.date = id
}
const initSelectList = () => {
  typeActions.value = [
    { text: t('bill_all'), id: 1 },
    { text: t('finance_transferIn'), id: 2 },
    { text: t('finance_transferOut'), id: 3 }
  ]
  dateActions.value = [
    { text: t('bill_week'), id: 1 },
    { text: t('bill_oneMonth'), id: 2 },
    { text: t('bill_trimester'), id: 3 },
    { text: t('bill_halfAYear'), id: 4 },
    { text: t('bill_oneYear'), id: 5 }
  ]
}
onBeforeMount(() => {
  initSelectList()
})
watch(
  () => t('home'),
  () => {
    initSelectList()
  }
)
</script>
<template>
  <div class="container">
    <div class="body w-100%">
      <div class="body_top mb-20 flex items-center justify-between mb-15">
        <div class="font-source text-[#fff] flex items-center">
          <div class="w-4 h-21 bg-#1675FD rounded-full"></div>
          <div class="title text-[22px] ml-10">{{ t('bill_title') }}</div>
        </div>
      </div>
      <div class="body_data bg-[#fff]/10 mb-40">
        <div class="flex items-center mb-22">
          <div class="flex flex-col items-center w-50%">
            <div class="text-[#A2B0C3] text-[14px] font-pingfang mb-11">{{ t('finance_totalAmount') }}(U)</div>
            <div class="text-[#fff] text-[24px] font-inter font-600">1,000.00</div>
          </div>
          <div class="flex flex-col items-center w-50%">
            <div class="text-[#A2B0C3] text-[14px] font-pingfang mb-11">{{ t('finance_cumulative') }}(U)</div>
            <div class="text-[#fff] text-[24px] font-inter font-600">1,000.00</div>
          </div>
        </div>
        <div class="px-15 flex items-center justify-between">
          <div>
            <van-popover v-model:show="showTypePopover" :actions="typeActions" @select="onTypeSelect"
              :show-arrow="false" :offset="[30, 10]">
              <template #reference>
                <div class="flex items-center font-microsoft">
                  <div class="text-[#A2B0C3] text-[12px] mr-[6px]">{{typeActions.find(item => item.id ==
                    selectData.type).text}}{{ t('bill_type') }}</div>
                  <svg xmlns="http://www.w3.org/2000/svg" width="8" height="6" viewBox="0 0 13 9" fill="none">
                    <path d="M6.5 9L0.00480921 -2.69824e-07L12.9952 8.65831e-07L6.5 9Z" fill="#A2B0C3" />
                  </svg>
                </div>
              </template>
              <template #action="{ action, index }">
                <div class="text-[#78859D] text-[12px] text-center w-100%">
                  <span :class="action.id == selectData.type ? 'text-[#000000]' : ''">{{
                    action.text
                  }}</span>
                </div>
              </template>
            </van-popover>
          </div>
          <div>
            <van-popover v-model:show="showDatePopover" :actions="dateActions" @select="onDateSelect"
              :show-arrow="false" :offset="[-30, 10]">
              <template #reference>
                <div class="flex items-center font-microsoft">
                  <div class="text-[#A2B0C3] text-[12px] mr-[6px]">{{dateActions.find(item => item.id ==
                    selectData.date).text}}</div>
                  <svg xmlns="http://www.w3.org/2000/svg" width="8" height="6" viewBox="0 0 13 9" fill="none">
                    <path d="M6.5 9L0.00480921 -2.69824e-07L12.9952 8.65831e-07L6.5 9Z" fill="#A2B0C3" />
                  </svg>
                </div>
              </template>
              <template #action="{ action, index }">
                <div class="text-[#78859D] text-[12px] text-center w-100%">
                  <span :class="action.id == selectData.date ? 'text-[#000000]' : ''">{{
                    action.text
                  }}</span>
                </div>
              </template>
            </van-popover>
          </div>
        </div>
      </div>
      <div class="flex flex-col gap-12 px-15">
        <div class="w-100% py-17 px-13 rounded-[7px] bg-[#fff]/10 font-pingfang" v-for="item in 3" :key="item">
          <div class="flex items-center justify-between w-100% mb-10">
            <div class="w-73 text-[#B8B8C0] text-[12px]">{{ t('bill_profit') }}：</div>
            <div class="text-[#fff] text-[12px] font-700 font-microsoft">+1,000.00</div>
          </div>
          <div class="flex items-center justify-between w-100%">
            <div class="w-73 text-[#B8B8C0] text-[12px]">{{ t('bill_time') }}：</div>
            <div class="text-[#B8B8C0] text-[12px]">2024-05-10 12:00</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.container {
  width: 100%;

  .body {
    padding: 20px 0px;
    min-height: calc(100vh - var(--van-nav-bar-height));
    background: url('@/static/imgs/lending/bg.png') no-repeat;
    background-size: 100% 100%;

    // padding: 20px 15px;
    &_top {
      padding-left: 15px;

      .bill {
        width: 72px;
        height: 32px;
        border-radius: 11px 0 0 11px;
        border: 1px solid #fff;
        background: rgba(255, 255, 255, 0.1);
        box-shadow: 0 4px 16px 0 rgba(0, 60, 255, 0.34), 0 0 10px 0 rgba(163, 192, 255, 0.57) inset;
        text-align: center;
        line-height: 32px;
      }
    }

    &_data {
      padding: 19px 0 15px;
    }
  }
}
</style>
